<?php
class M_DbTable_CruiseItineraryTour extends Apps_Db_Table_Abstract {
	protected $_name = 'cruise_itinerary_tour';

	const STATUS_ACTIVE  	= 1;
	const STATUS_INACTIVE  	= 0;
	const STATUS_DELETED  	= -1;

	const SPECIAL_OFFER_TRUE 	= 1;
	const SPECIAL_OFFER_FALSE 	= 0;
	
	const BEST_SELLING_TRUE 	= 1;
	const BEST_SELLING_FALSE 	= 0;

	public function getList() {
		$q = $this->_db
				  ->select()
				  ->from(array('c_i_t'   => $this->_name), null)
				  ->join(array('c' => 'cruise'), 'c.id = c_i_t.cruise_id', null)
				  ->join(array('c_i' => 'cruise_itinerary'), 'c_i.id = c_i_t.cruise_itinerary_id', null)
				  ->join(array('a' 	 => 'article'), 'a.reference_id = c_i_t.id', null)
				  ->where('a.reference_type =?', M_DbTable_Article::REFERENCE_TYPE_CRUISE)
				  ->where('c_i_t.status !=?', self::STATUS_DELETED)
				  ->order('c_i_t.created_date DESC')
				  ->columns(
				  		array('id'							=>  'c_i_t.id',
				  		      'special_offer'           	=>  'c_i_t.special_offer',
				  		      'best_selling'           		=>  'c_i_t.best_selling',
				  		      'status'                  	=>  'c_i_t.status',
							  'cruise_id'					=>	'c.id',
							  'name'						=>	'c.name',
							  'en_name'						=>	'c.en_name',
							  'en_title'					=>	'a.en_title',
							  'cruise_itinerary_id'	    	=>	'c_i.id',
							  'cruise_itinerary_en_code'	=>	'c_i.en_code',
				  ));
		return $q;
	}

	public function getCruiseItineraryTour($id) {
		$q = $this->_db
				  ->select()
				  ->from(array('c_i_t'   => $this->_name), null)
				  ->join(array('c' => 'cruise'), 'c.id = c_i_t.cruise_id', null)
				  ->join(array('c_i' => 'cruise_itinerary'), 'c_i.id = c_i_t.cruise_itinerary_id', null)
				  ->join(array('a' 	 => 'article'), 'a.reference_id = c_i_t.id', null)
				  ->where('a.reference_type =?', M_DbTable_Article::REFERENCE_TYPE_CRUISE)
				  ->where('c_i_t.status !=?', self::STATUS_DELETED)
				  ->where('c_i_t.id =?', $id)
				  ->columns(
				  		array('id'					=>  'c.id',
				  		      'special_offer'       =>  'c_i_t.special_offer',
				  		      'best_selling'        =>  'c_i_t.best_selling',
				  		      'status'              =>  'c_i_t.status',
							  'special_offer'		=>	'c_i_t.special_offer',
							  'description'			=>	'c_i_t.description',
							  'meta_keyword'		=>	'c_i_t.meta_keyword',
							  'meta_description'	=>	'c_i_t.meta_description',
							  'header_title'		=>	'c_i_t.header_title',
				  				
							  'cruise_id'			=>	'c.id',
							  'cruise_itinerary_id'	=>	'c_i.id',

							  'title'				=>	'a.title',
							  'en_title'			=>	'a.en_title',
				  			  'overview'			=>	'a.overview',
				  			  'en_overview'			=>	'a.en_overview',
				  			  'detail'				=>	'a.detail',
				  			  'en_detail'			=>	'a.en_detail'
				  ));
		return $q;
	}
}